// pages/input/input.js
import Toast from '../../miniprogram/miniprogram_npm/@vant/weapp/toast/toast';
const request=require('../../util/request.js')
const navBarHeight = wx.getSystemInfoSync().statusBarHeight + 44;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status:0,
    states:[
      '全部',
      '未完成',
      '已完成'
    ],
    date:"",
    type:1,
    account_id:0,
    activeNames:0,
    logs:[],
    account:{
      title:"加载中",
      color:"#5779E7"
    }
  },
  bindChangeStatus(e){
    this.setData({
      status: e.detail.value
    })

    this.getMeetAndReceivable();
  },
  getMeetAndReceivable(){

    var that = this;
    request.requestAjax('company/getMeetAndReceivable',{id:that.data.account_id,date:that.data.date,status:that.data.status},"加载中",function(res){
        if(res.status==200){
            that.setData({
              logs:res.data
            })
            return false;
        }else{
          wx.showToast({
            title: '请求失败',
            icon:"none"
          })
        }
  
    },function(res){
      wx.showToast({
        title: '请求失败',
        icon:"none"
      })
    });
  },
  delLog(e){
    var id = e.currentTarget.dataset.id
    var that = this;
    wx.showModal({
      title: '提示',
      content: '您确定删除此记录吗？',
      success: function (res) {
        if (res.confirm) { //这里是点击了确定以后
          that.removeLog(id);
        } 
      }
    })
  },
  removeLog(id){


    var that = this;
    var data = that.data;
    request.requestAjax('meet_receivable/removeMeetReceivable',{id:id},"正在删除",function(res){
        if(res.status==200){
          wx.showToast({
            title: '删除成功',
            icon:"success"
          })
          setTimeout(function(){
              that.getAccountInfo();
              that.getMeetAndReceivable()
          },300);
            return false;
        }else{
          wx.showToast({
            title: res.msg,
            icon:"none"
          })
        }

    },function(res){
      wx.showToast({
        title: '提交失败',
        icon:"none"
      })
    });
  },
  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },
  onClickLeft() {
    wx.navigateBack();
  },
  onClickRight() {
    wx.showToast({ title: '点击按钮', icon: 'none' });
  },

  goPage(event){
    // console.log(event);
    if(event.currentTarget.dataset.pageurl=="/pages/register/register"){
      Toast('暂未开放注册~');
    }

    wx.navigateTo({
      url: event.currentTarget.dataset.pageurl,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(this.data.states)
    this.setData({
      account_id:options.id,
      date:new Date().getFullYear(),
      type:options.type
    });
    this.getMeetAndReceivable();
    this.getAccountInfo();
  },
  bindDateChange(e){
    this.setData({
      date:e.detail.value
    })

    this.getAccountInfo()
  },
  getAccountInfo(){
    var that = this;
    request.requestAjax('company/meetAndReceivableInfo',{id:that.data.account_id,date:that.data.date},"加载中",function(res){
        if(res.status==200){
            that.setData({
              account:res.data.account
            });
            console.log(that.data.account)
            return false;
        }else{
          wx.showToast({
            title: '请求失败',
            icon:"none"
          })
        }
  
    },function(res){
      wx.showToast({
        title: '请求失败',
        icon:"none"
      })
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})